<template>
    <div class="form-single-fragment" style="position: relative;">
      <el-form ref="ProjectList" :model="formData" class="full-width-input" :rules="rules"
               style="width: 100%" label-width="100px" :size="defaultFormItemSize"
               label-position="right" @submit.native.prevent>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="项目ID" prop="SysProject.Id">
              <el-input class="input-item" v-model="formData.SysProject.id"
                        :clearable="true" placeholder="项目ID" :disabled="isEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目名称" prop="SysProject.name">
              <el-input class="input-item" v-model="formData.SysProject.name" :clearable="true" placeholder="项目名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="上级部门ID" prop="SysProject.parentId">
              <el-input-number class="input-item" v-model="formData.SysProject.parentId" :clearable="true" placeholder="上级部门ID"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="子项目id" prop="SysProject.childIds">
              <el-input-number class="input-item" v-model="formData.SysProject.childIds" :clearable="true" placeholder="子项目id"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目编码" prop="SysProject.code">
              <el-input class="input-item" v-model="formData.SysProject.code" :clearable="true" placeholder="项目编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目时期" prop="SysProject.projectPeriod">
              <el-input class="input-item" v-model="formData.SysProject.projectPeriod" :clearable="true" placeholder="项目时期"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="公路等级" prop="SysProject.roadLevel">
              <el-input class="input-item" v-model="formData.SysProject.roadLevel" :clearable="true" placeholder="公路等级"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="前期施工图阶段数" prop="SysProject.orderNum">
              <el-input-number class="input-item" v-model="formData.SysProject.orderNum" :clearable="true" placeholder="前期施工图阶段数"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="排序" prop="SysProject.drawingLevel">
              <el-input-number class="input-item" v-model="formData.SysProject.drawingLevel" :clearable="true" placeholder="排序"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="序号2" prop="SysProject.orderNum2">
              <el-input-number class="input-item" v-model="formData.SysProject.orderNum2" :clearable="true" placeholder="序号2"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目概况" prop="SysProject.projectSummary">
              <el-input class="input-item" v-model="formData.SysProject.projectSummary" :clearable="true" placeholder="项目概况"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="创建者id" prop="SysProject.creatorId">
              <el-input class="input-item" v-model="formData.SysProject.creatorId" :clearable="true" placeholder="创建者id"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="创建时间" prop="SysProject.gmtCreate">
              <el-date-picker class="input-item" v-model="formData.SysProject.gmtCreate"
                        :clearable="true" placeholder="创建时间" :disabled="isEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态标记" prop="SysProject.status">
              <el-input class="input-item" v-model="formData.SysProject.status" :clearable="true" placeholder="状态标记"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开工令日期" prop="SysProject.startDate">
              <el-date-picker class="input-item" v-model="formData.SysProject.startDate"
                              :clearable="true" placeholder="开工令日期"
                              format="yyyy-MM-dd" value-format="yyyy-MM-dd 00:00:00"
                              type="date" align="left"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="交工日期" prop="SysProject.finishDate">
              <el-date-picker class="input-item" v-model="formData.SysProject.finishDate"
                              :clearable="true" placeholder="交工日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="竣工日期" prop="SysProject.endDate">
              <el-date-picker class="input-item" v-model="formData.SysProject.endDate" :clearable="true" placeholder="竣工日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="建设单位" prop="SysProject.buildId">
              <el-input class="input-item" v-model="formData.SysProject.buildId" :clearable="true" placeholder="建设单位"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="总公司" prop="SysProject.headOfficeId">
              <el-input class="input-item" v-model="formData.SysProject.headOfficeId" :clearable="true" placeholder="总公司"/>
            </el-form-item>
          </el-col>
          <el-col :span="24" class="gutter-bottom">
            <el-row class="no-scroll flex-box" type="flex" justify="end">
              <el-button type="primary" v-if="!isEdit" :size="defaultFormItemSize"
                         @click="onAddClick()">
                新增
              </el-button>
              <el-button type="primary" v-if="isEdit" :size="defaultFormItemSize"
                         @click="onUpdateClick()">
                保存
              </el-button>
              <el-button type="primary" :size="defaultFormItemSize" :plain="true"
                         @click="onCancel(false)">
                取消
              </el-button>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </div>
</template>

<script>

  import { findTreeNode, findTreeNodePath, findItemFromList } from '@/utils';
  import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js';
  import { uploadMixin, statsDateRangeMixin } from '@/core/mixins';
  import { SysProjectController, DictionaryController } from '@/api';
    export default {
      name: "projectForm",
      props:{
        id: {
          default: undefined
        }
      },
      mixins: [uploadMixin,statsDateRangeMixin],
      data () {
        return {
          formData: {
            SysProject: {
              id: undefined,
              name: undefined,
              parentId: undefined,
              childIds: undefined,
              code: undefined,
              projectPeriod: undefined,
              roadLevel: undefined,
              drawingLevel: undefined,
              orderNum: undefined,
              orderNum2: undefined,
              projectSummary: undefined,
              creatorId: undefined,
              gmtCreate: undefined,
              status: undefined,
              startDate: undefined,
              finishDate: undefined,
              endDate: undefined,
              buildId: undefined,
              headOfficeId: undefined,
              shorthand: undefined,
              remark: undefined,
              subgradeWidth: undefined,
              pavement: undefined,
              fileId: undefined,
              phase: undefined,
              workDate: undefined,
              approvalDate: undefined,
              manager: undefined,
              contact: undefined,
              length: undefined,
              actualConstructionLength: undefined,
              completeUsedLength: undefined,
              replayInvest: undefined,
              addInvest: undefined,
              settleInvest: undefined,
              finalAccountsAmount: undefined,
              docNo: undefined,
              permitApprovalNumber: undefined,
              initialDesignApprovalNumber: undefined,
              drawingDesignApprovalNumber: undefined,
              proprietorsSupplyMaterialsBudget: undefined,
              contractAmount: undefined,
              downFloatFee: undefined,
              provisionalAmount: undefined,
              isDatasourceInit: false
            }
          },
          rules:{
            'Project.name': [
              {required: true, message: '项目名称不能为空', trigger: 'blur'}
            ],
          },
          ProjectList: {
            formFilter: {
            },
            formFilterCopy: {
            },
            btnGroup: {
              isInit: false
            },
            isInit: false
          },
        }
      },
      methods: {
        onCancel (isSuccess, data) {
          if (this.observer != null) {
            this.observer.cancel(isSuccess, data);
          }
        },
        refreshProjectList (reloadData = false) {
          this.loadProject().then(res => {
            if (!this.ProjectList.isInit) {
              // 初始化下拉数据
            }
            this.ProjectList.isInit = true;
          }).catch(e => {});
        },
        /**
         * 新增
         */
        onAddClick () {

        },
        /**
         * 编辑
         */
        onUpdateClick () {

        },
        /**
         * 获取详细信息
         */
        loadProject () {
          alert("loadProject:"+this.id);
          return new Promise((resolve, reject) => {
            if (!this.formData.SysProject.isDatasourceInit) {
              if (this.id == null) {
                this.resetFormData();
                reject();
                return;
              }
              let params = {
                id: this.id
              };
              SysProjectController.view(this,params).then(res => {
                this.formData.SysProject = {...res.data,isDatasourceInit:true};
              }).catch(e => {
                reject();
              });
            } else {
              this.formData.SysProject.isDatasourceInit = true;
              resolve();
            }
          });
        },
        resetFormData () {
          this.formData = {
            Project:{
              id: undefined,
              name: undefined,
              parentId: undefined,
              childIds: undefined,
              code: undefined,
              projectPeriod: undefined,
              roadLevel: undefined,
              drawingLevel: undefined,
              orderNum: undefined,
              orderNum2: undefined,
              projectSummary: undefined,
              creatorId: undefined,
              gmtCreate: undefined,
              status: undefined,
              startDate: undefined,
              finishDate: undefined,
              endDate: undefined,
              buildId: undefined,
              headOfficeId: undefined,
              shorthand: undefined,
              remark: undefined,
              subgradeWidth: undefined,
              pavement: undefined,
              fileId: undefined,
              phase: undefined,
              workDate: undefined,
              approvalDate: undefined,
              manager: undefined,
              contact: undefined,
              length: undefined,
              actualConstructionLength: undefined,
              completeUsedLength: undefined,
              replayInvest: undefined,
              addInvest: undefined,
              settleInvest: undefined,
              finalAccountsAmount: undefined,
              docNo: undefined,
              permitApprovalNumber: undefined,
              initialDesignApprovalNumber: undefined,
              drawingDesignApprovalNumber: undefined,
              proprietorsSupplyMaterialsBudget: undefined,
              contractAmount: undefined,
              downFloatFee: undefined,
              provisionalAmount: undefined,
              isDatasourceInit: false
            }
          }
        },
        formInit () {
          this.refreshProjectList();
        }
      },
      computed: {
        isEdit () {
          return this.id != null && this.id !== '';
        }
      },
      mounted () {
        // 初始化页面数据
        this.formInit();
      },
    }
</script>

<style scoped>

</style>
